package com.beamfield.controller.manage.lab;

import com.alibaba.fastjson.JSON;
import com.beamfield.common.ApiResult;
import com.beamfield.common.CommonUtils;
import com.beamfield.common.PageResult;
import com.beamfield.controller.common.BaseController;
import com.beamfield.model.ChemicalConfig;
import com.beamfield.model.ChemicalReceiving;
import com.beamfield.model.ChemicalWaste;
import com.beamfield.model.LabChemical;
import com.beamfield.enums.HttpResultEnum;
import com.beamfield.model.*;
import com.beamfield.modelVo.FileInfoVo;
import com.beamfield.service.manage.lab.ManageService;
import com.beamfield.service.manage.sys.FileService;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.*;

@Controller
@RequestMapping("/cms/lab/labmanage")
public class ManageController extends BaseController{

    @Autowired
    private ManageService manageService;

    @RequestMapping(value = "/system_file", method = RequestMethod.GET)
    public ModelAndView system_file() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/system_file2", method = RequestMethod.GET)
    public ModelAndView system_file2() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/system_file3", method = RequestMethod.GET)
    public ModelAndView system_file3() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/system_file4", method = RequestMethod.GET)
    public ModelAndView system_file4() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/manage", method = RequestMethod.GET)
    public ModelAndView manage() {
        return new ModelAndView();
    }

    @RequestMapping(value = "/detection",method = RequestMethod.GET)
    public ModelAndView detection(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/material_detec_unpass",method = RequestMethod.GET)
    public ModelAndView material_detec_unpass(){
        return new ModelAndView();
    }
    @RequestMapping(value = "/material_detec_manage",method = RequestMethod.GET)
    public ModelAndView material_detec_manage(){
        return new ModelAndView();
    }
    //化学药品管理
    @RequestMapping(value = "/chemicalManage", method = RequestMethod.GET)
    public ModelAndView chemicalManage() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/editChemical", method = RequestMethod.GET)
    public ModelAndView editChemical() {
        return new ModelAndView();
    }
    //化学药品领用管理
    @RequestMapping(value = "/chemicalReceivingManage", method = RequestMethod.GET)
    public ModelAndView chemicalReceivingManage() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/editChemicalReceiving", method = RequestMethod.GET)
    public ModelAndView editChemicalReceiving() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/lab_standardsub", method = RequestMethod.GET)
    public ModelAndView lab_standardsub() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/addStandardsub", method = RequestMethod.GET)
    public ModelAndView addStandardsub() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/out_unit", method = RequestMethod.GET)
    public ModelAndView out_unit() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/addComment", method = RequestMethod.GET)
    public ModelAndView addComment() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/out_unit_manage", method = RequestMethod.GET)
    public ModelAndView out_unit_manage() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/editStandardsub", method = RequestMethod.GET)
    public ModelAndView editStandardsub() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/lab_sfile", method = RequestMethod.GET)
    public ModelAndView lab_sfile() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/addSfile", method = RequestMethod.GET)
    public ModelAndView addSfile() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/editSfile", method = RequestMethod.GET)
    public ModelAndView editSfile() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/lab_curing", method = RequestMethod.GET)
    public ModelAndView lab_curing() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/addCuring", method = RequestMethod.GET)
    public ModelAndView addCuring() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/editCuring", method = RequestMethod.GET)
    public ModelAndView editCuring() {
        return new ModelAndView();
    }


    /**
     * 标准文件导出
     * @param response
     * @param name
     * @param type
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/exportSfile")
    @ResponseBody
    public String exportDetail(HttpServletResponse response, String name, String type, HttpServletRequest request,String start,String end,String offset,String limit) throws Exception {
        Long beam_id = super.getBeamId(request);
        String apiResult = manageService.exportSfile(type, response, name, beam_id,start,end,offset,limit);
        return apiResult;
    }
    @RequestMapping("/exportMixDesign")
    @ResponseBody
    public String exportMixDesign(HttpServletResponse response, String entrust_num, HttpServletRequest request,String start,String end,String offset,String limit,String status) throws Exception {
        Long beam_id = super.getBeamId(request);
        String apiResult = manageService.exportMixDesign(response, entrust_num, beam_id,start,end,offset,limit,status);
        return apiResult;
    }
    @RequestMapping("/exportMixCons")
    @ResponseBody
    public String exportMixCons(HttpServletResponse response, String notice_id,String part_date, HttpServletRequest request,String offset,String limit) throws Exception {
        Long beam_id = super.getBeamId(request);
        String apiResult = manageService.exportMixDesign( response, notice_id, beam_id,offset,limit,part_date);
        return apiResult;
    }


    @RequestMapping("/exportConcreteEntrust")
    @ResponseBody
    public String exportConcreteEntrust(HttpServletResponse response, String name, HttpServletRequest request,String start,String end,
                                        String offset,String limit,String status
    ) throws Exception {
        Long beam_id = super.getBeamId(request);
        String apiResult = manageService.exportConcreteEntrust( response, name, beam_id,start,end,offset,limit,status);
        return apiResult;
    }
    @RequestMapping("/exportStandardsub")
    @ResponseBody
    public String exportStandardsub(HttpServletResponse response, String name, HttpServletRequest request,String start,String end,
                                        Long offset,Integer limit
    ) throws Exception {
        Long beam_id = super.getBeamId(request);
        String apiResult = manageService.exportStandardsub( response, name, beam_id,start,end,offset,limit);
        return apiResult;
    }
    @RequestMapping("/exportRectific")
    @ResponseBody
    public String exportRectific(HttpServletResponse response, HttpServletRequest request,
                                        Long offset,Integer limit
    ) throws Exception {
        Long beam_id = super.getBeamId(request);
        String apiResult = manageService.exportRectific(beam_id,offset,limit,response);
        return apiResult;
    }
    @RequestMapping("/exportCuring")
    @ResponseBody
    public String exportCuring(HttpServletResponse response, HttpServletRequest request,
                                        Long offset,Integer limit,String no
    ) throws Exception {
        Long beam_id = super.getBeamId(request);
        String apiResult = manageService.exportCuring(beam_id,offset,limit,response,no);
        return apiResult;
    }
    /**
     * 获取化学药品列表
     * @param offset
     * @param limit
     * @param storage_location
     * @param chemical_name
     * @return
     */
    @RequestMapping("/getChemicalList")
    @ResponseBody
    public PageResult getChemicalList(Integer offset, Integer limit, String storage_location, String chemical_name, HttpServletRequest request){
        Long beam_id = super.getBeamId(request);
        return manageService.getChemicalList(offset,limit,storage_location,chemical_name,beam_id);
    }

    /**
     * 删除化学药品
     * @return
     */
    @RequestMapping("/delChemical")
    @ResponseBody
    public ApiResult delChemical(String id){
        ApiResult apiResult=new ApiResult();
        if (StringUtils.isNotBlank(id)) {
            return manageService.delChemical(id);
        }else  {
            apiResult.setMessage("未获取到要删除的化学药品");
            apiResult.setCode("500");
            return  apiResult;
        }
    }

    @RequestMapping("/getChemicalInfo")
    @ResponseBody
    public ApiResult getChemicalInfo(Long id, HttpSession session) {
        ApiResult apiResult = new ApiResult();

        Map<String, Object> map = new HashMap<String, Object>();
        LabChemical labChemical = manageService.getChemicalInfo(id);

        map.put("labChemical", labChemical);
        apiResult.setResult(map);
        return apiResult;
    }
    /**
     * 新增或编辑化学药品
     *
     * @param labChemical
     * @return
     */
    @RequestMapping("/doEditChemical")
    @ResponseBody
    public ApiResult doEditChemical(LabChemical labChemical, HttpServletRequest request) {
        Long user_id = super.getUserId(request);
        Long beam_id = super.getBeamId(request);

        labChemical.setUpdater(user_id);
        labChemical.setUpdatetime(new Date());
        labChemical.setBeam_id(beam_id);

        try {
            //新增
            if (labChemical.getId() == null) {
                //药品名称不可重复
                if(manageService.selectByChemicalName(labChemical.getChemical_name(),beam_id)!=null){
                    return new ApiResult("1", "该药品已存在！");
                }

                labChemical.setOperator(user_id);
                labChemical.setAddtime(new Date());
                manageService.insertChemical(labChemical);
            }
            //编辑
            else {
                manageService.updateChemical(labChemical);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult("1", "服务器异常！");
        }
        return new ApiResult("2", "成功！");
    }
    /**
     * 化学药品导入
     * @param request
     * @param multipartFile
     * @return
     */
    @RequestMapping(value = "/importChemical", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult importChemical(HttpServletRequest request, @RequestParam("excelFile") MultipartFile multipartFile) {
        Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);

        if (multipartFile == null) {
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        try {
            long fileId = super.saveFile((CommonsMultipartFile) multipartFile);
            InputStream in = multipartFile.getInputStream();
            byte[] data = IOUtils.toByteArray(in);
            Workbook wb = null;
            FormulaEvaluator formulaEvaluator;
            try {
                wb = new HSSFWorkbook(new ByteArrayInputStream(data));
                formulaEvaluator = new HSSFFormulaEvaluator((HSSFWorkbook) wb);
            } catch (Exception e) {
                wb = new XSSFWorkbook(new ByteArrayInputStream(data));
                formulaEvaluator = new XSSFFormulaEvaluator((XSSFWorkbook) wb);
            }
            return manageService.importChemical(wb,fileId,userId,beamId,formulaEvaluator);
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }
    /**
     * 获取化学药品下拉框
     * @return
     */
    @RequestMapping("/getAllChemicalName")
    @ResponseBody
    public List<String> getAllChemicalName(HttpServletRequest request){
        Long beam_id = super.getBeamId(request);
        return manageService.getAllChemicalName(beam_id);
    }

    /**
     * 样品编号下拉框
     * @param request
     * @return
     */
    @RequestMapping("/getSampleNo")
    @ResponseBody
    public List<String> getSampleNo(HttpServletRequest request){
        Long beam_id = super.getBeamId(request);
        return manageService.getSampleNo(beam_id);
    }
    /**
     * 获取化学药品领用记录列表
     * @param offset
     * @param limit
     * @param chemical_name
     * @return
     */
    @RequestMapping("/getChemicalReceivingList")
    @ResponseBody
    public PageResult getChemicalReceivingList(Integer offset, Integer limit,String chemical_name, HttpServletRequest request){
        Long beam_id = super.getBeamId(request);
        return manageService.getChemicalReceivingList(offset,limit,chemical_name,beam_id);
    }
    /**
     * 新增化学药品领用记录
     *
     * @param chemicalReceiving
     * @return
     */
    @RequestMapping("/doEditChemicalReceiving")
    @ResponseBody
    public ApiResult doEditChemicalReceiving(ChemicalReceiving chemicalReceiving, HttpServletRequest request) {
        Long user_id = super.getUserId(request);
        Long beam_id = super.getBeamId(request);

        return manageService.insertChemicalReceiving(chemicalReceiving,user_id,beam_id);
    }

    /**
     * 内页资料管理修改监理审批状态/是否归档
     * @param request
     * @param satate
     * @param id
     * @param type
     * @return
     */
    @RequestMapping("/saveInboundCheckState")
    @ResponseBody
    public ApiResult saveInboundCheckState(HttpServletRequest request, int satate, long id, String type){
        Long userId = super.getUserId(request);
        ApiResult apiResult = manageService.saveInboundCheckState(satate, id, type, userId);
        return  apiResult;
    }

    /**
     * 保存检查整改状态
     * @param request
     * @param id
     * @param time
     * @return
     */
    @RequestMapping("/saveRectific")
    @ResponseBody
    public ApiResult saveRectific(HttpServletRequest request, long id, String time){
        Long userId = super.getUserId(request);
        ApiResult apiResult = manageService.saveRectific(id,time,userId);
        return  apiResult;
    }

    /**
     * 溶液配制记录
     */
    @RequestMapping(value = "/chemicalConfigManage", method = RequestMethod.GET)
    public ModelAndView chemicalConfigManage() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/editChemicalConfig", method = RequestMethod.GET)
    public ModelAndView editChemicalConfig() {
        return new ModelAndView();
    }
    /**
     * 获取溶液配制记录列表
     * @param offset
     * @param limit
     * @param chemical_name
     * @param config_date
     * @return
     */
    @RequestMapping("/getChemicalConfigList")
    @ResponseBody
    public PageResult getChemicalConfigList(Integer offset, Integer limit,String chemical_name, String config_date,HttpServletRequest request){
        Long beam_id = super.getBeamId(request);
        return manageService.getChemicalConfigList(offset,limit,chemical_name,config_date,beam_id);
    }
    /**
     * 新增溶液配制记录
     *
     * @param chemicalConfig
     * @return
     */
    @RequestMapping("/doEditChemicalConfig")
    @ResponseBody
    public ApiResult doEditChemicalConfig(ChemicalConfig chemicalConfig, HttpServletRequest request) {
        Long user_id = super.getUserId(request);
        Long beam_id = super.getBeamId(request);

        chemicalConfig.setUpdater(user_id);
        chemicalConfig.setUpdatetime(new Date());
        chemicalConfig.setBeam_id(beam_id);

        try {
            //新增
            if (chemicalConfig.getId() == null) {
                chemicalConfig.setOperator(user_id);
                chemicalConfig.setAddtime(new Date());
                manageService.insertChemicalConfig(chemicalConfig);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult("1", "服务器异常！");
        }
        return new ApiResult("2", "成功！");
    }


    /**
     * 废液处理记录
     */
    @RequestMapping(value = "/chemicalWasteManage", method = RequestMethod.GET)
    public ModelAndView chemicalWasteManage() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/editChemicalWaste", method = RequestMethod.GET)
    public ModelAndView editChemicalWaste() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/lab_curing_tem", method = RequestMethod.GET)
    public ModelAndView lab_curing_tem() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/addCuringTem", method = RequestMethod.GET)
    public ModelAndView addCuringTem() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/editTem", method = RequestMethod.GET)
    public ModelAndView editTem() {
        return new ModelAndView();
    }
    /**
     * 获取废液处理记录列表
     * @param offset
     * @param limit
     * @param chemical_name
     * @return
     */
    @RequestMapping("/getChemicalWasteList")
    @ResponseBody
    public PageResult getChemicalWasteList(Integer offset, Integer limit,String chemical_name,HttpServletRequest request){
        Long beam_id = super.getBeamId(request);
        return manageService.getChemicalWasteList(offset,limit,chemical_name,beam_id);
    }
    /**
     * 新增废液处理记录
     *
     * @param chemicalWaste
     * @return
     */
    @RequestMapping("/doEditChemicalWaste")
    @ResponseBody
    public ApiResult doEditChemicalWaste(ChemicalWaste chemicalWaste, HttpServletRequest request) {
        Long user_id = super.getUserId(request);
        Long beam_id = super.getBeamId(request);

        chemicalWaste.setUpdater(user_id);
        chemicalWaste.setUpdatetime(new Date());
        chemicalWaste.setBeam_id(beam_id);

        try {
            //新增
            if (chemicalWaste.getId() == null) {
                chemicalWaste.setOperator(user_id);
                chemicalWaste.setAddtime(new Date());
                manageService.insertChemicalWaste(chemicalWaste);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult("1", "服务器异常！");
        }
        return new ApiResult("2", "成功！");
    }

    @RequestMapping("/saveInboundCheckIsBack")
    @ResponseBody
    public ApiResult saveInboundCheckIsBack(HttpServletRequest request, int isback, String  back_date,long id){
        Long userId = super.getUserId(request);
        ApiResult apiResult = manageService.saveInboundCheckIsBack(isback, id, back_date, userId);
        return  apiResult;
    }

    /**
     * 委外资质评价新增
     * @param commentJson
     * @param request
     * @param multipartFile
     * @return
     */
    @RequestMapping("/saveComment")
    @ResponseBody
    public ApiResult saveComment(
            @RequestParam("commentJson") String commentJson,
            HttpServletRequest request, @RequestParam(value="comm_file",required = false) MultipartFile multipartFile){
       Long userId = super.getUserId(request);
        Long beamId = super.getBeamId(request);
        if(StringUtils.isEmpty(commentJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        try {
            LabOutUnit labOutUnit = JSON.parseObject(commentJson, LabOutUnit.class);

            if(multipartFile != null) {
                long fileId = super.saveFile((CommonsMultipartFile) multipartFile);
                labOutUnit.setAppr_file(fileId);
            }
            ApiResult apiResult = manageService.saveComment(userId, beamId, labOutUnit);
            return apiResult;
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }

    /**
     * 标准物质管理列表添加
     * @param request
     * @param detailJson
     * @return
     */
    @RequestMapping("/addStandardsubList")
    @ResponseBody
    public ApiResult saveStandardsubList( HttpServletRequest request, String detailJson){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        if(StringUtils.isEmpty(detailJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        return manageService.addStandardsubList(detailJson, beamId, userId);
    }

    /**
     * 养护室样品出入登记添加
     * @param request
     * @param detailJson
     * @return
     */
    @RequestMapping("/addCuringList")
    @ResponseBody
    public ApiResult addCuringList( HttpServletRequest request, String detailJson){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        if(StringUtils.isEmpty(detailJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        return manageService.addCuringList(detailJson, beamId, userId);
    }

    /**
     * 养护室温湿度登记
     * @param request
     * @param detailJson
     * @return
     */
    @RequestMapping("/addCuringTemList")
    @ResponseBody
    public ApiResult addCuringTemList( HttpServletRequest request, String detailJson){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        if(StringUtils.isEmpty(detailJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        return manageService.addCuringTemList(detailJson, beamId, userId);
    }

    /**
     * 标准规范文件清单添加
     * @param request
     * @param detailJson
     * @return
     */
    @RequestMapping("/addSfileList")
    @ResponseBody
    public ApiResult addSfileList( HttpServletRequest request, String detailJson){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        if(StringUtils.isEmpty(detailJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        return manageService.addSfileList(detailJson, beamId, userId);
    }

    /**
     * 检查整改添加
     * @param request
     * @param detailJson
     * @return
     */
    @RequestMapping("/addRectificList")
    @ResponseBody
    public ApiResult addRectificList( HttpServletRequest request, String detailJson){
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        if(StringUtils.isEmpty(detailJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        return manageService.addRectificList(detailJson, beamId, userId);
    }

    /**
     * 保存标准物资
     * @param request
     * @return
     */
    @RequestMapping("/saveStandardsub")
    @ResponseBody
    public ApiResult saveStandardsub(HttpServletRequest request){
        String standardsubJson = request.getParameter("standardsubJson");
        if(StringUtils.isEmpty(standardsubJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        int result;
        try{
            LabStandardsub labStandardsub = JSON.parseObject(standardsubJson, LabStandardsub.class);
            result = manageService.saveStandardsub(labStandardsub, beamId, userId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }

    /**
     * 修改标准规范文件清单时的单个保存
     * @param request
     * @return
     */
    @RequestMapping("/saveSfile")
    @ResponseBody
    public ApiResult saveSfile(HttpServletRequest request){
        String standardsubJson = request.getParameter("objectJson");
        if(StringUtils.isEmpty(standardsubJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        int result;
        try{
            LabSfile labSfile = JSON.parseObject(standardsubJson, LabSfile.class);
            result = manageService.saveSfile(labSfile, beamId, userId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }

    /**
     * 养护室温湿度登记修改
     * @param request
     * @return
     */
    @RequestMapping("/saveTem")
    @ResponseBody
    public ApiResult saveTem(HttpServletRequest request){
        String standardsubJson = request.getParameter("objectJson");
        if(StringUtils.isEmpty(standardsubJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        int result;
        try{
            LabCuringTemphu labCuringTemphu = JSON.parseObject(standardsubJson, LabCuringTemphu.class);
            result = manageService.saveLabCuringTemphu(labCuringTemphu, beamId, userId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }

    /**
     * 单个养护室样品出入登记修改保存
     * @param request
     * @return
     */
    @RequestMapping("/saveCuring")
    @ResponseBody
    public ApiResult saveCuring(HttpServletRequest request){
        String standardsubJson = request.getParameter("objectJson");
        if(StringUtils.isEmpty(standardsubJson)){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
        Long beamId = super.getBeamId(request);
        Long userId = super.getUserId(request);
        int result;
        try{
            LabCuring labCuring = JSON.parseObject(standardsubJson, LabCuring.class);
            result = manageService.saveCuring(labCuring, beamId, userId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
        if (result == 0) {
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        } else {
            return new ApiResult(HttpResultEnum.SUCCESS.getCode(), "保存成功");
        }
    }

    /**
     * 获取标准物质列表
     * @param request
     * @param offset
     * @param limit
     * @return
     */
    @RequestMapping("getStandardsubList")
    @ResponseBody
    public  PageResult getStandardsubList(HttpServletRequest request,Long offset,int limit,String standardsub_name){
        Long beamId = super.getBeamId(request);
        String start = request.getParameter("start");
        String end = request.getParameter("end");
       return manageService.getStandardsubList(beamId, offset, limit,standardsub_name,start,end);
    }

    /**
     * 检查整改列表获取
     * @param request
     * @param offset
     * @param limit
     * @return
     */
    @RequestMapping("getRectificList")
    @ResponseBody
    public  PageResult getRectificList(HttpServletRequest request,Long offset,int limit){
        Long beamId = super.getBeamId(request);
       return manageService.getRectificList(beamId, offset, limit);
    }

    /**
     * 养护室样品出入登记列表获取
     * @param request
     * @param offset
     * @param limit
     * @param sample_no
     * @return
     */
    @RequestMapping("getCuringList")
    @ResponseBody
    public  PageResult getCuringList(HttpServletRequest request,Long offset,int limit,String sample_no){
        Long beamId = super.getBeamId(request);
       return manageService.getCuringList(beamId, offset, limit,sample_no);
    }

    /**
     * 获取委外评价列表
     * @param request
     * @param offset
     * @param limit
     * @return
     */
    @RequestMapping("getCommentList")
    @ResponseBody
    public  PageResult getCommentList(HttpServletRequest request,Long offset,int limit){
        Long beamId = super.getBeamId(request);
       return manageService.getCommentList(beamId, offset, limit);
    }

    /**
     * 标准规范文件清单列表
     * @param request
     * @param offset
     * @param limit
     * @param name
     * @param type
     * @return
     */
    @RequestMapping("getSfileList")
    @ResponseBody
    public  PageResult getSfileList(HttpServletRequest request,Long offset,int limit,String name,int type,String start,String end){
        Long beamId = super.getBeamId(request);
       return manageService.getSfileList(beamId, offset, limit,name,type,start,end);
    }

    /**
     * 养护温度列表
     * @param request
     * @param offset
     * @param limit
     * @param type
     * @return
     */
    @RequestMapping("getCuringTemList")
    @ResponseBody
    public  PageResult getCuringTemList(HttpServletRequest request,Long offset,int limit,int type,String date){
        Long beamId = super.getBeamId(request);
       return manageService.getCuringTemList(beamId, offset, limit,type,date);
    }


    /**
     * 获取标准物质
     * @return
     */
    @RequestMapping("getStandardsub")
    @ResponseBody
    public  ApiResult getStandardsub(Long id){
        if (id==0){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
       return manageService.getStandardsub(id);
    }

    /**
     * 修改标准文件回显用 id查询单个标准文件
     * @param id
     * @return
     */
    @RequestMapping("getSile")
    @ResponseBody
    public  ApiResult getSile(Long id){
        if (id==0){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
       return manageService.getSile(id);
    }

    /**
     * id查询养护温度
     * @param id
     * @return
     */
    @RequestMapping("getTem")
    @ResponseBody
    public  ApiResult getTem(Long id){
        if (id==0){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
       return manageService.getTem(id);
    }

    /**
     * 获取委外单位资质
     * @param id
     * @return
     */
    @RequestMapping("/getComment")
    @ResponseBody
    public  ApiResult getComment(Long id){
        if (id==0){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
       return manageService.getComment(id);
    }

    /**
     * 养护室样品id获取单个
     * @param id
     * @return
     */
    @RequestMapping("/getCuring")
    @ResponseBody
    public  ApiResult getCuring(Long id){
        if (id==0){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
       return manageService.getCuring(id);
    }
    /**
     * 删除标准物质
     * @return
     */
    @RequestMapping("delStandardsub")
    @ResponseBody
    public  ApiResult delStandardsub(Long id){
        if (id==0){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
       return manageService.delStandardsub(id);
    }

    /**
     * 删除养护温度记录
     * @param id
     * @return
     */
    @RequestMapping("delTem")
    @ResponseBody
    public  ApiResult delTem(Long id){
        if (id==0){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
       return manageService.delTem(id);
    }

    /**
     * 删除养护室样品
     * @param id
     * @return
     */
    @RequestMapping("delCuring")
    @ResponseBody
    public  ApiResult delCuring(Long id){
        if (id==0){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
       return manageService.delCuring(id);
    }

    /**
     * 删除标准清单文件
     * @param id
     * @return
     */
    @RequestMapping("delSfile")
    @ResponseBody
    public  ApiResult delSfile(Long id){
        if (id==0){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }
       return manageService.delSfile(id);
    }

    /**
     * 文件转发
     */
    @RequestMapping(value = "/fileForwardManage", method = RequestMethod.GET)
    public ModelAndView fileForwardManage() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/editFileForward", method = RequestMethod.GET)
    public ModelAndView editFileForward() {
        return new ModelAndView();
    }
    /**
     * 获取文件转发列表
     * @param offset
     * @param limit
     * @param file_no
     * @param start_time
     *  @param end_time
     * @return
     */
    @RequestMapping("/getFileForwardList")
    @ResponseBody
    public PageResult getFileForwardList(Integer offset, Integer limit,String file_no, String start_time,String end_time,HttpServletRequest request){
        Long beam_id = super.getBeamId(request);
        return manageService.getFileForwardList(offset,limit,file_no,start_time,end_time,beam_id);
    }

    @RequestMapping("/getFileForwardInfo")
    @ResponseBody
    public ApiResult getFileForwardInfo(Long id,HttpSession session) {
        ApiResult apiResult = new ApiResult();

        Map<String, Object> map = new HashMap<String, Object>();
        LabFileForward labFileForward = manageService.getFileForwardInfo(id);

        map.put("labFileForward", labFileForward);
        apiResult.setResult(map);
        return apiResult;
    }
    /**
     * 新增or编辑文件转发
     *
     * @param labFileForward
     * @return
     */
    @RequestMapping("/doEditFileForward")
    @ResponseBody
    public ApiResult doEditFileForward(LabFileForward labFileForward, HttpServletRequest request) {
        Long user_id = super.getUserId(request);
        Long beam_id = super.getBeamId(request);

        labFileForward.setUpdater(user_id);
        labFileForward.setUpdatetime(new Date());
        labFileForward.setBeam_id(beam_id);

        try {
            //新增
            if (labFileForward.getId() == null) {
                List<LabFileForward> labFileForwards = manageService.selectByFile_no(labFileForward.getFile_no());
                if(labFileForwards!=null || !labFileForwards.isEmpty()){
                    return new ApiResult("1", "该文件编号已存在！");
                }
                labFileForward.setOperator(user_id);
                labFileForward.setAddtime(new Date());
                manageService.insertFileForward(labFileForward);
            }
            //编辑
            else {
                manageService.updateFileForward(labFileForward);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult("1", "服务器异常！");
        }
        return new ApiResult("2", "成功！");
    }
    /**
     * 删除文件转发
     * @return
     */
    @RequestMapping("/delFileForward")
    @ResponseBody
    public ApiResult delFileForward(String id){
        ApiResult apiResult=new ApiResult();
        if (StringUtils.isNotBlank(id)) {
            return manageService.delFileForward(id);
        }else  {
            apiResult.setMessage("未获取到要删除的文件转发记录");
            apiResult.setCode("500");
            return  apiResult;
        }
    }

    /**
     * 样品管理
     */

    @RequestMapping(value = "/sampleManage", method = RequestMethod.GET)
    public ModelAndView sampleManage() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/editSample", method = RequestMethod.GET)
    public ModelAndView editSample() {
        return new ModelAndView();
    }
    /**
     * 获取样品列表
     * @param offset
     * @param limit
     * @param sample_name
     * @param sample_date
     * @return
     */
    @RequestMapping("/getSampleList")
    @ResponseBody
    public PageResult getSampleList(Integer offset, Integer limit,String sample_name, String sample_date,HttpServletRequest request){
        Long beam_id = super.getBeamId(request);
        return manageService.getSampleList(offset,limit,sample_name,sample_date,beam_id);
    }

    @RequestMapping("/getSampleInfo")
    @ResponseBody
    public ApiResult getSampleInfo(Long id,HttpSession session) {
        ApiResult apiResult = new ApiResult();

        Map<String, Object> map = new HashMap<String, Object>();
        LabSample labSample = manageService.getSampleInfo(id);

        map.put("labSample", labSample);
        apiResult.setResult(map);
        return apiResult;
    }
    /**
     * 新增or编辑样品
     *
     * @param labSample
     * @return
     */
    @RequestMapping("/doEditSample")
    @ResponseBody
    public ApiResult doEditSample(LabSample labSample, HttpServletRequest request) {
        Long user_id = super.getUserId(request);
        Long beam_id = super.getBeamId(request);

        labSample.setUpdater(user_id);
        labSample.setUpdatetime(new Date());
        labSample.setBeam_id(beam_id);

        try {
            //新增
            if (labSample.getId() == null) {
                if(manageService.selectBySample_no(labSample.getSample_no())!=null){
                    return new ApiResult("1", "该样品编号已存在！");
                }


                //默认未处理
                labSample.setIshandel(2);

                labSample.setOperator(user_id);
                labSample.setAddtime(new Date());
                manageService.insertSample(labSample);
            }
            //编辑
            else {
                manageService.updateSample(labSample);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult("1", "服务器异常！");
        }
        return new ApiResult("2", "成功！");
    }
    /**
     * 删除样品
     * @return
     */
    @RequestMapping("/delSample")
    @ResponseBody
    public ApiResult delSample(String id){
        ApiResult apiResult=new ApiResult();
        if (StringUtils.isNotBlank(id)) {
            return manageService.delSample(id);
        }else  {
            apiResult.setMessage("未获取到要删除的样品");
            apiResult.setCode("500");
            return  apiResult;
        }
    }
    /**
     * 获取样品下拉框
     * @return
     */
    @RequestMapping("/getAllSample")
    @ResponseBody
    public List<LabSample> getAllSample(HttpServletRequest request){
        Long beam_id = super.getBeamId(request);
        return manageService.getAllSample(beam_id);
    }

    /**
     * 样品处理管理
     */

    @RequestMapping(value = "/sampleHandleManage", method = RequestMethod.GET)
    public ModelAndView sampleHandleManage() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/editSampleHandle", method = RequestMethod.GET)
    public ModelAndView editSampleHandle() {
        return new ModelAndView();
    }
    /**
     * 获取样品处理列表
     * @param offset
     * @param limit
     * @param sample_name
     * @param handle_date
     * @return
     */
    @RequestMapping("/getSampleHandleList")
    @ResponseBody
    public PageResult getSampleHandleList(Integer offset, Integer limit,String sample_name, String handle_date,HttpServletRequest request){
        Long beam_id = super.getBeamId(request);
        return manageService.getSampleHandleList(offset,limit,sample_name,handle_date,beam_id);
    }

    @RequestMapping("/getSampleHandleInfo")
    @ResponseBody
    public ApiResult getSampleHandleInfo(Long id,HttpSession session) {
        ApiResult apiResult = new ApiResult();

        Map<String, Object> map = new HashMap<String, Object>();
        LabSampleHandle labSampleHandle = manageService.getSampleHandleInfo(id);

        map.put("labSampleHandle", labSampleHandle);
        apiResult.setResult(map);
        return apiResult;
    }
    /**
     * 新增or编辑样品处理
     *
     * @param labSampleHandle
     * @return
     */
    @RequestMapping("/doEditSampleHandle")
    @ResponseBody
    public ApiResult doEditSampleHandle(LabSampleHandle labSampleHandle, HttpServletRequest request) {
        Long user_id = super.getUserId(request);
        Long beam_id = super.getBeamId(request);

        labSampleHandle.setUpdater(user_id);
        labSampleHandle.setUpdatetime(new Date());
        labSampleHandle.setBeam_id(beam_id);

        try {
            //新增
            if (labSampleHandle.getId() == null) {
                LabSample labSample = manageService.selectBySample_no(labSampleHandle.getSample_no());
                if(labSample.getIshandel()==1){
                    return new ApiResult("1", "该样品已处理！");
                }


                labSampleHandle.setOperator(user_id);
                labSampleHandle.setAddtime(new Date());
                manageService.insertSampleHandle(labSampleHandle);

                //更新样品处理情况

                labSample.setIshandel(1);
                manageService.updateSample(labSample);

            }
            //编辑
            else {
                manageService.updateSampleHandle(labSampleHandle);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult("1", "服务器异常！");
        }
        return new ApiResult("2", "成功！");
    }

    /**
     * 样品留样管理
     */

    @RequestMapping(value = "/sampleClaimManage", method = RequestMethod.GET)
    public ModelAndView sampleClaimManage() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/rectific", method = RequestMethod.GET)
    public ModelAndView rectific() {
        return new ModelAndView();
    }
    @RequestMapping(value = "/addRectific", method = RequestMethod.GET)
    public ModelAndView addRectific() {
        return new ModelAndView();
    }

    @Autowired
    FileService fileService;

    /**
     * 获取样品留样要求

     * @return
     */
    @RequestMapping("/getSampleClaimInfo")
    @ResponseBody
    public ApiResult getSampleClaimInfo(HttpServletRequest request) {
        Long beam_id = super.getBeamId(request);
        ApiResult apiResult = new ApiResult();

        Map<String, Object> map = new HashMap<String, Object>();
        Lab lab = manageService.selectByBeam_id(beam_id);
        if(lab!=null){
            FileInfo fileInfo = fileService.getFileById(lab.getSample_claim());
            if(fileInfo!=null){
                map.put("file_id", fileInfo.getFileid());
                map.put("file_url", CommonUtils.getFielUrl(fileInfo));
            }
        }

        apiResult.setResult(map);
        return apiResult;
    }
    /**
     * 上传样品留样要求
     *
     * @param file_id
     * @return
     */
    @RequestMapping("/doEditSampleClaim")
    @ResponseBody
    public ApiResult doEditSampleClaim(Long file_id, HttpServletRequest request) {
        Long beam_id = super.getBeamId(request);
        try {
            Lab lab = manageService.selectByBeam_id(beam_id);
            if(lab!=null){
                lab.setSample_claim(file_id);
                manageService.updateLab(lab);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult("1", "服务器异常！");
        }
        return new ApiResult("2", "上传成功！");
    }
    /**
     * 上传试验管理标准化手册
     *
     * @param file_id
     * @return
     */
    @RequestMapping("/doEditSystemFile")
    @ResponseBody
    public ApiResult doEditSystemFile(Long file_id, HttpServletRequest request) {
        Long beam_id = super.getBeamId(request);
        try {
            Lab lab = manageService.selectByBeam_id(beam_id);
            if(lab!=null){
                List<String> file_ids = new ArrayList<>();
                if(lab.getExtend2()!=null){
                    for(String s:lab.getExtend2().split(",")){
                        if(StringUtils.isNotEmpty(s)) {
                            file_ids.add(s);
                        }
                    }
                }
                file_ids.add(file_id.toString());
                lab.setExtend2(StringUtils.join(file_ids.toArray(),","));
                manageService.updateLab(lab);
            }else{
                return new ApiResult("1", "请先完善试验室基本信息");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult("1", "服务器异常！");
        }
        return new ApiResult("2", "上传试验管理标准化手册成功！");
    }
    /**
     * 获取试验管理标准化手册
     *
     * @return
     */
    @RequestMapping("/getSystemFile")
    @ResponseBody
    public List<FileInfoVo> getSystemFile(HttpServletRequest request) {
        Long beam_id = super.getBeamId(request);
        List<FileInfoVo> result = new ArrayList<>();
        try {
            Lab lab = manageService.selectByBeam_id(beam_id);
            if (lab != null) {
                if (lab.getExtend2() != null) {
                    for (String file_id : lab.getExtend2().split(",")) {
                        result.add(fileService.getFileInfoVo(Long.parseLong(file_id)));
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    /**
     * 上传质量手册
     *
     * @param file_id
     * @return
     */
    @RequestMapping("/doEditSystemFile2")
    @ResponseBody
    public ApiResult doEditSystemFile2(Long file_id, HttpServletRequest request) {
        Long beam_id = super.getBeamId(request);
        try {
            Lab lab = manageService.selectByBeam_id(beam_id);
            if(lab!=null){
                List<String> file_ids = new ArrayList<>();
                if(lab.getExtend3()!=null){
                    for(String s:lab.getExtend3().split(",")){
                        if(StringUtils.isNotEmpty(s)) {
                            file_ids.add(s);
                        }
                    }
                }
                file_ids.add(file_id.toString());
                lab.setExtend3(StringUtils.join(file_ids.toArray(),","));
                manageService.updateLab(lab);
            }else{
                return new ApiResult("1", "请先完善试验室基本信息");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult("1", "服务器异常！");
        }
        return new ApiResult("2", "上传质量手册成功！");
    }
    /**
     * 获取质量手册
     *
     * @return
     */
    @RequestMapping("/getSystemFile2")
    @ResponseBody
    public List<FileInfoVo> getSystemFile2(HttpServletRequest request) {
        Long beam_id = super.getBeamId(request);
        List<FileInfoVo> result = new ArrayList<>();
        try {
            Lab lab = manageService.selectByBeam_id(beam_id);
            if (lab != null) {
                if (lab.getExtend3() != null) {
                    for (String file_id : lab.getExtend3().split(",")) {
                        result.add(fileService.getFileInfoVo(Long.parseLong(file_id)));
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    /**
     * 上传程序文件
     *
     * @param file_id
     * @return
     */
    @RequestMapping("/doEditSystemFile3")
    @ResponseBody
    public ApiResult doEditSystemFile3(Long file_id, HttpServletRequest request) {
        Long beam_id = super.getBeamId(request);
        try {
            Lab lab = manageService.selectByBeam_id(beam_id);
            if(lab!=null){
                List<String> file_ids = new ArrayList<>();
                if(lab.getExtend4()!=null){
                    for(String s:lab.getExtend4().split(",")){
                        if(StringUtils.isNotEmpty(s)) {
                            file_ids.add(s);
                        }
                    }
                }
                file_ids.add(file_id.toString());
                lab.setExtend4(StringUtils.join(file_ids.toArray(),","));
                manageService.updateLab(lab);
            }else{
                return new ApiResult("1", "请先完善试验室基本信息");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult("1", "服务器异常！");
        }
        return new ApiResult("2", "上传程序文件成功！");
    }
    /**
     * 获取程序文件
     *
     * @return
     */
    @RequestMapping("/getSystemFile3")
    @ResponseBody
    public List<FileInfoVo> getSystemFile3(HttpServletRequest request) {
        Long beam_id = super.getBeamId(request);
        List<FileInfoVo> result = new ArrayList<>();
        try {
            Lab lab = manageService.selectByBeam_id(beam_id);
            if (lab != null) {
                if (lab.getExtend4() != null) {
                    for (String file_id : lab.getExtend4().split(",")) {
                        result.add(fileService.getFileInfoVo(Long.parseLong(file_id)));
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    /**
     * 上传作业指导书
     *
     * @param file_id
     * @return
     */
    @RequestMapping("/doEditSystemFile4")
    @ResponseBody
    public ApiResult doEditSystemFile4(Long file_id, HttpServletRequest request) {
        Long beam_id = super.getBeamId(request);
        try {
            Lab lab = manageService.selectByBeam_id(beam_id);
            if(lab!=null){
                List<String> file_ids = new ArrayList<>();
                if(lab.getExtend5()!=null){
                    for(String s:lab.getExtend5().split(",")){
                        if(StringUtils.isNotEmpty(s)) {
                            file_ids.add(s);
                        }
                    }
                }
                file_ids.add(file_id.toString());
                lab.setExtend5(StringUtils.join(file_ids.toArray(),","));
                manageService.updateLab(lab);
            }else{
                return new ApiResult("1", "请先完善试验室基本信息");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ApiResult("1", "服务器异常！");
        }
        return new ApiResult("2", "上传作业指导书成功！");
    }
    /**
     * 获取作业指导书
     *
     * @return
     */
    @RequestMapping("/getSystemFile4")
    @ResponseBody
    public List<FileInfoVo>getSystemFile4(HttpServletRequest request) {
        Long beam_id = super.getBeamId(request);
        List<FileInfoVo> result = new ArrayList<>();
        try {
            Lab lab = manageService.selectByBeam_id(beam_id);
            if (lab != null) {
                if (lab.getExtend5() != null) {
                    for (String file_id : lab.getExtend5().split(",")) {
                        result.add(fileService.getFileInfoVo(Long.parseLong(file_id)));
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @Value("${session.beam}")
    private String beam;

    /**
     * 导出化学药品
     *
     * @param response
     * @param offset
     * @param limit
     * @param storage_location
     * @param chemical_name
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/exportChemical")
    @ResponseBody
    public String exportChemical(HttpServletResponse response, Integer offset, Integer limit, String storage_location, String chemical_name, HttpSession session) throws Exception {
        Long beam_id = (Long) session.getAttribute(beam);
        return manageService.exportChemical(response,offset,limit,storage_location,chemical_name,beam_id);
    }
    /**
     * 导出化学药品领用记录
     *
     * @param response
     * @param offset
     * @param limit
     * @param chemical_name
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/exportChemicalReceiving")
    @ResponseBody
    public String exportChemicalReceiving(HttpServletResponse response, Integer offset, Integer limit, String chemical_name, HttpSession session) throws Exception {
        Long beam_id = (Long) session.getAttribute(beam);
        return manageService.exportChemicalReceiving(response,offset,limit,chemical_name,beam_id);
    }

    /**
     * 导出溶液配制
     *
     * @param response
     * @param offset
     * @param limit
     * @param chemical_name
     * @param config_date
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/exportChemicalConfig")
    @ResponseBody
    public String exportChemicalConfig(HttpServletResponse response, Integer offset, Integer limit,  String chemical_name, String config_date, HttpSession session) throws Exception {
        Long beam_id = (Long) session.getAttribute(beam);
        return manageService.exportChemicalConfig(response,offset,limit,chemical_name,config_date,beam_id);
    }

    /**
     * 导出废液处理记录
     *
     * @param response
     * @param offset
     * @param limit
     * @param chemical_name
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/exportChemicalWaste")
    @ResponseBody
    public String exportChemicalWaste(HttpServletResponse response, Integer offset, Integer limit, String chemical_name, HttpSession session) throws Exception {
        Long beam_id = (Long) session.getAttribute(beam);
        return manageService.exportChemicalWaste(response,offset,limit,chemical_name,beam_id);
    }

    /**
     * 导出样品留样
     *
     * @param response
     * @param offset
     * @param limit
     * @param sample_name
     * @param sample_date
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/exportSample")
    @ResponseBody
    public String exportSample(HttpServletResponse response, Integer offset, Integer limit,  String sample_name, String sample_date, HttpSession session) throws Exception {
        Long beam_id = (Long) session.getAttribute(beam);
        return manageService.exportSample(response,offset,limit,sample_name,sample_date,beam_id);
    }

    /**
     * 导出样品处理
     *
     * @param response
     * @param offset
     * @param limit
     * @param sample_name
     * @param handle_date
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/exportSampleHandle")
    @ResponseBody
    public  String exportSampleHandle(HttpServletResponse response, Integer offset, Integer limit,  String sample_name, String handle_date, HttpSession session) throws Exception {
        Long beam_id = (Long) session.getAttribute(beam);
        return manageService.exportSampleHandle(response,offset,limit,sample_name,handle_date,beam_id);
    }

    /**
     * 导出文件转发
     *
     * @param response
     * @param file_no
     * @param start_time
     * @param end_time
     * @param session
     * @return
     * @throws Exception
     */
    @RequestMapping("/exportFileForward")
    @ResponseBody
    public  void exportFileForward(HttpServletResponse response, String file_no, String start_time, String end_time, HttpSession session) throws Exception {
        Long beam_id = (Long) session.getAttribute(beam);
        manageService.exportFileForward(beam_id,file_no,start_time,end_time,response);
    }
}
